local rolely_aoshi = fk.CreateSkill {
    name = "rolely_aoshi",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
    ["rolely_aoshi"] = "傲世",
    [":rolely_aoshi"] = "锁定技，每轮结束时，除你外，没有手牌的角色失去一点体力，有牌的角色展示一张手牌，若颜色均相同，所有角色展示牌的角色失去一点体力；" ..
        "随后，你获得其中的红色牌，弃置其中的黑色牌，然后摸两种颜色差值的牌。",
}

rolely_aoshi:addEffect(fk.RoundEnd, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(rolely_aoshi.name)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x = 0
        for _, id in ipairs(room:getOtherPlayers(player)) do
            if id:getHandcardNum() == 0 then
                room:loseHp(id, 1, rolely_aoshi.name)
                x = x + 1
            end
        end
        if x == #room.alive_players - 1 then return end
        local targets = table.filter(room:getOtherPlayers(player), function(p)
            return not p:isKongcheng()
        end)
        if #targets == 0 then return end
        room:doIndicate(player, targets)
        local result = room:askToJointCards(player, {
            players = targets,
            min_num = 1,
            max_num = 1,
            include_equip = false,
            skill_name = rolely_aoshi.name,
            prompt = "傲世：请选择一张牌展示",
            cancelable = false,
        })
        local cards = {}
        for p, ids in pairs(result) do
            if table.contains(p:getCardIds("h"), ids[1]) then
                p:showCards(ids)
                table.insert(cards, ids[1])
            end
        end
        if player.dead or #cards == 0 then return end
        local red = {}
        local black = {}
        for _, card in ipairs(cards) do
            if Fk:getCardById(card).color == Card.Red then
                table.insertIfNeed(red, Fk:getCardById(card))
            end
            if Fk:getCardById(card).color == Card.Black then
                table.insertIfNeed(black, Fk:getCardById(card))
            end
        end
        local n = math.abs(#red - #black)
        if #red == 0 or #black == 0 then
            for _, id in ipairs(targets) do
                room:loseHp(id, 1, rolely_aoshi.name)
            end
        end
        if #red > 0 then
            room:moveCardTo(red, Card.PlayerHand, player, fk.ReasonJustMove, rolely_aoshi.name, nil, true, player)
        end
        if #black > 0 then
            room:moveCardTo(black, Card.DiscardPile, nil, fk.ReasonJustMove, rolely_aoshi.name, nil, true, player)
        end
        player:drawCards(n, rolely_aoshi.name)
    end,
})
return rolely_aoshi
